<?php

class admin_template_system_log_listing extends admin_theme
{


	protected function center()
	{
	    $logs = $this->get('logs');

		$ui_listing = bone::get_admin_ui('listing');

		$options = array();
		$options['0'] = '所有';
		foreach($this->get('admins') as $admin)
		{
		    $options[$admin->id] = $admin->username;
		}
		
		$ui_listing->set_filter(
            array(
            	'type'=>'text', 
            	'name'=>'key', 
            	'label'=>'搜索', 
            	'value'=>$this->get('key'), 
            	'width'=>'100px'
            ), 
            array(
            	'type'=>'select', 
                'name'=>'user_id', 
            	'label'=>'指定管理员', 
            	'options'=>$options,
                'value'=>$this->get('user_id')
            )
		);

		$lib_ip = bone::get_lib('ip');
		
		$date = '';
		foreach($logs as $log)
		{
		    $new_date = date('Y-m-d',$log->time);
		    if($date==$new_date)
		    {
		        $log->time = '<span style="visibility:hidden;">'. $new_date .' &nbsp;</span>'. date('H:i:s',$log->time);
		    }
		    else
		    {
		        $log->time = $new_date .' &nbsp;'. date('H:i:s',$log->time);
		        $date = $new_date;
		    }			
			$log->username = bone::get_user($log->user_id)->username;
			$log->address = $lib_ip->convert($log->ip);
		}
		
		$ui_listing->set_data($logs);
		
		$ui_listing->set_fields(
            array(
    			'name'=>'time',
    			'label'=>'时间',
    			'align'=>'center',
    		    'width'=>'150'
    		),
    		array(
    			'name'=>'username',
    			'label'=>'用户名',
    			'align'=>'center',
    		    'width'=>'120'
    		),
    		array(
    			'name'=>'title',
    			'label'=>'操作',
    			'align'=>'left'
    		),
    		array(
    			'name'=>'ip',
    			'label'=>'IP',
    			'align'=>'center',
    		    'width'=>'120'
    		),
    		array(
    			'name'=>'address',
    			'label'=>'地理位置',
    			'align'=>'left',
    		    'width'=>'200'
    		)
		);

		$ui_listing->set_pagination( $this->get('pagination') );
		$ui_listing->display();
	}	

}
?>